package com.shop.service.impl;

import com.shop.entity.UserRole;
import com.shop.mapper.UserRoleMapper;
import com.shop.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service("userRoleService")
public class UserRoleServiceImpl implements UserRoleService {

    @Autowired
    UserRoleMapper userRoleMapper;


    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public int add(UserRole userRole) throws Exception {
        try {
            return userRoleMapper.add(userRole);
        } catch (Exception e) {
            throw new Exception("添加异常！");
        }
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public int update(UserRole userRole) throws Exception {
        try {
            return userRoleMapper.update(userRole);
        } catch (Exception e) {
            throw new Exception("更新异常！");
        }
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public int del(UserRole userRole) throws Exception {
        try {
            return userRoleMapper.del(userRole);
        } catch (Exception e) {
            throw new Exception("删除异常！");
        }
    }

    @Override
    public UserRole get(UserRole userRole) {
        return userRoleMapper.get(userRole);
    }

    @Override
    public List<UserRole> getList(UserRole userRole) {
        return userRoleMapper.getList(userRole);
    }
}
